Skip to content
This repository has been archived by the owner on Aug 1, 2023. It is now read-only.

[rfr] Allow subnets to have no gateway #553

Merged
merged 2 commits into from
Apr 7, 2016
Merged

[rfr] Allow subnets to have no gateway #553

merged 2 commits into from
Apr 7, 2016

Conversation

jtopjian
Copy link
Contributor

@jtopjian jtopjian commented Apr 7, 2016

If the gateway_ip parameter is omitted, Neutron assigns a default gateway of .1. However, if gateway_ip exists, but is null, then no gateway is assigned.

This patch is trying to emulate the --no-gateway command-line option of the python-neutronclient app:

https://github.com/openstack/python-neutronclient/blob/master/neutronclient/neutron/v2_0/subnet.py#L120-L123

@@ -108,6 +108,7 @@ type CreateOpts struct {
TenantID string
AllocationPools []AllocationPool
GatewayIP string
NoGateway bool
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be *bool? I don't understand why EnableDHCP is *bool.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The zero-value for bool is false, so there's no way to check if a user set the field to false or just didn't provide it. With a *bool, we know that if the value is true or false it was provided by the user, because otherwise it'd be nil.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. The issue I ran into is that an omission of EnableDHCP was turning DHCP on. I did a scan through the Neutron code and couldn't find where DHCP would be turned on if enable_dhcp was omitted, but it was.

By having the direct value of EnableDHCP passed through, that would have been avoided. See here: https://github.com/hashicorp/terraform/pull/6052/files

So I'm wondering if NoGateway should be bool or *bool. IMO, the former makes sense and is more intuitive, but having a bool and *bool attribute in the struct seems to complicate the structure.

Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the default is reasonable, bool is fine, and we use it elsewhere in the library like that. The Neturon OpenStack docs aren't good, so I'm sure we just didn't know that enabling DHCP was the default. Otherwise we probably would've named it DisableDHCP and made it a bool.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I'll keep NoGateway at bool. I think the zero-value shouldn't cause any issues with how this is implemented.

Re DHCP: I had no idea, either. I was just inquiring to see if I was overlooking something, there was past history, if I was going crazy, etc 😄

@coveralls
Copy link

Coverage Status

Coverage increased (+0.005%) to 80.057% when pulling f92ae6c on jtopjian:subnet-no-gateway into 1270499 on rackspace:master.

@@ -139,6 +140,8 @@ func (opts CreateOpts) ToSubnetCreateMap() (map[string]interface{}, error) {
}
if opts.GatewayIP != "" {
s["gateway_ip"] = opts.GatewayIP
} else if opts.NoGateway {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be an error to provide NoGateway == true and GatewayIP != "". We should probably check for that at the beginning of this if block. Also the one in Update.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you're right. I was taking the cheap way out by thinking if a user has both set, they have more problems to worry about 😉

@jtopjian
Copy link
Contributor Author

jtopjian commented Apr 7, 2016

@jrperritt Invalid gateway config checks added.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.01%) to 80.065% when pulling 705cd9d on jtopjian:subnet-no-gateway into 1270499 on rackspace:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.01%) to 80.065% when pulling 705cd9d on jtopjian:subnet-no-gateway into 1270499 on rackspace:master.

@jtopjian
Copy link
Contributor Author

jtopjian commented Apr 7, 2016

@jrperritt err.. just noticed my commit message was incorrect (s/can/cannot/g). Just fixed that and forced the push.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.01%) to 80.065% when pulling 2524d11 on jtopjian:subnet-no-gateway into 1270499 on rackspace:master.

@jrperritt
Copy link
Contributor

+2

@jrperritt jrperritt merged commit a09b5b4 into rackspace:master Apr 7, 2016
@jtopjian
Copy link
Contributor Author

jtopjian commented Apr 7, 2016

Thank you!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants